//
//  HZJTopOfCell.swift
//  WeiBo
//
//  Created by 陈贵 on 15/9/12.
//  Copyright © 2015年 hzj. All rights reserved.
//

import UIKit

class HZJTopOfCell: UIView {

    /// 模型
    var statusesViewModel:StatusesViewModel?{
        didSet{
            iconView.sd_setImageWithURL(statusesViewModel?.userIconUrl)
            nameLable.text = statusesViewModel?.statuses.user?.name
            memberView.image = statusesViewModel!.userMemberImage
//            timeLable.text = statusesViewModel?.statuses.created_at
//            sourceLabel.text = statusesViewModel?.statuses.source
            vipView.image = statusesViewModel?.userVipImage
            
            
        
        }
    }
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = UIColor.whiteColor()
        setUI()
    }
   required init?(coder aDecoder: NSCoder) {
       fatalError("init(coder:) has not been implemented")
   }

/// 加载界面
    private func setUI(){
        
        addSubview(iconView)
        addSubview(nameLable)
        addSubview(memberView)
        addSubview(timeLable)
        addSubview(sourceLabel)
        addSubview(vipView)
        
        
        //约束
        //头像
        iconView.translatesAutoresizingMaskIntoConstraints = false
        addConstraint(NSLayoutConstraint(item: iconView, attribute: NSLayoutAttribute.Left, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Left, multiplier: 1, constant: HZJMargin))
        addConstraint(NSLayoutConstraint(item: iconView, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Top, multiplier: 1, constant: HZJMargin))
        addConstraint(NSLayoutConstraint(item: iconView, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: 40))
        addConstraint(NSLayoutConstraint(item: iconView, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: 40))

        //昵称
        nameLable.translatesAutoresizingMaskIntoConstraints = false
        addConstraint(NSLayoutConstraint(item: nameLable, attribute: NSLayoutAttribute.Left, relatedBy: NSLayoutRelation.Equal, toItem: iconView, attribute: NSLayoutAttribute.Right, multiplier: 1, constant: HZJMargin))
        addConstraint(NSLayoutConstraint(item: nameLable, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: iconView, attribute: NSLayoutAttribute.Top, multiplier: 1, constant: 0))
        
        //会员标识
        memberView.translatesAutoresizingMaskIntoConstraints = false
        addConstraint(NSLayoutConstraint(item: memberView, attribute: NSLayoutAttribute.Left, relatedBy: NSLayoutRelation.Equal, toItem: nameLable, attribute: NSLayoutAttribute.Right, multiplier: 1, constant: HZJMargin))
        addConstraint(NSLayoutConstraint(item: memberView, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: nameLable, attribute: NSLayoutAttribute.Top, multiplier: 1, constant: 0))
        
        //时间
        timeLable.translatesAutoresizingMaskIntoConstraints = false
        addConstraint(NSLayoutConstraint(item: timeLable, attribute: NSLayoutAttribute.Left, relatedBy: NSLayoutRelation.Equal, toItem: iconView, attribute: NSLayoutAttribute.Right, multiplier: 1, constant: HZJMargin))
        addConstraint(NSLayoutConstraint(item: timeLable, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: iconView, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: 0))
        
        //来源
        sourceLabel.translatesAutoresizingMaskIntoConstraints = false
        addConstraint(NSLayoutConstraint(item: sourceLabel, attribute: NSLayoutAttribute.Left, relatedBy: NSLayoutRelation.Equal, toItem: timeLable, attribute: NSLayoutAttribute.Right, multiplier: 1, constant: HZJMargin))
        addConstraint(NSLayoutConstraint(item: sourceLabel, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: timeLable, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: 0))
        
        //等级
        vipView.translatesAutoresizingMaskIntoConstraints = false
        addConstraint(NSLayoutConstraint(item: vipView, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: iconView, attribute: NSLayoutAttribute.Right, multiplier: 1, constant: 0))
        addConstraint(NSLayoutConstraint(item: vipView, attribute: NSLayoutAttribute.CenterY, relatedBy: NSLayoutRelation.Equal, toItem: iconView, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: 0))
        
    }
    
///MARK: -  懒加载控件
    ///头像
    private lazy var iconView:UIImageView = UIImageView(image: UIImage(named: "avatar_default_big"))
/// 昵称
    private lazy var nameLable :UILabel = UILabel(title:"姓名", color: UIColor.orangeColor(), fontSize: 14)
    ///会员类型
    private lazy var memberView:UIImageView = UIImageView(image: UIImage(named: "common_icon_membership_level1"))
/// 时间
    private lazy var timeLable:UILabel = UILabel(title: "刚刚", color: UIColor.orangeColor(), fontSize: 10)
/// 来源
    private lazy var sourceLabel:UILabel = UILabel(title: "自远方", color: UIColor.blackColor(), fontSize: 10)
    ///会员等级
    private lazy var vipView:UIImageView = UIImageView(image: UIImage(named: "avatar_grassroot"))

}
